package cn.cj.erp.common.constants;

/**
 * 错误码枚举
 *
 * @author chenjian
 */
public enum BizCodeEnum {
    OK(200, "成功"),
    NO_PARAM(101, "传入参数缺失,请检查"),
    ERR_PARAM(102, "传入参数异常,请检查"),
    VALID_FAIL_PARAM(103, "参数校验异常"),
    SENTINEL_FLOW_ERROR(127, "请求过于频繁，被限流了"),
    SENTINEL_DEGRADE_ERROR(128, "请求被降级了"),
    SENTINEL_PARAM_FLOW_ERROR(129, "热点数据请求过于频繁"),
    SENTINEL_SYSTEM_ERROR(130, "请求过于频繁，触发系统限制"),
    SENTINEL_AUTHORITY_ERROR(131, "授权规则不通过"),
    FAIL(500, "操作失败，请重试"),
    FAIL_SAVE(501, "保存失败"),
    FAIL_UPDATE(502, "更新失败"),
    FAIL_DELETE(503, "删除失败"),
    FAIL_GET(504, "查询失败"),
    FAIL_NO_DATA(505, "无数据"),
    FAIL_USER(506, "用户不存在"),
    FAIL_PASS(507, "密码错"),
    EXIST_PHONE(601, "手机号已存在"),
    EXIST_EMAIL(602, "邮箱已存在"),
    EXIST_USERNAME(603, "用户名已存在"),
    UNKNOWN(999, "未知操作！！");

    private final Integer code;
    private final String msg;

    BizCodeEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static BizCodeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (BizCodeEnum resMsgEnum : values()) {
            if (resMsgEnum.code.equals(code)) {
                return resMsgEnum;
            }
        }
        return UNKNOWN;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
